#include "ButtonDragToolBox.h"
#include<QDrag>
#include<QMouseEvent>
#include<QMimeData>
#include<QVariant>
#include<QApplication>
ButtonDragToolBox::ButtonDragToolBox(QWidget *parent)
	: QToolBox(parent)
{
}

ButtonDragToolBox::~ButtonDragToolBox()
{
}

void ButtonDragToolBox::mouseMoveEvent(QMouseEvent* event)
{

    if (!(event->buttons() & Qt::LeftButton)) {
        return;
    }
    QDrag* drag = new QDrag(this);
    GraphicsItemMimeData* mimeData = new GraphicsItemMimeData;
    mimeData->currentDragInfo = itemCfgDragInfo;

    if (itemCfgDragInfo.stateSrcMap.contains(0)) {
        QPixmap pm(QApplication::applicationDirPath() + "/" + itemCfgDragInfo.stateSrcMap.value(0));
        drag->setPixmap(pm.scaled(60, 60));
    }
   
    mimeData->setProperty("XWaterItemCfgData", QVariant::fromValue(itemCfgDragInfo));//also ok;
    drag->setMimeData(mimeData);

    drag->exec(Qt::CopyAction | Qt::MoveAction);
}
